﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using umbraco.presentation.nodeFactory;
using System.Text;
using System.Configuration;
using System.Text.RegularExpressions;
using log4net;
using System.Reflection;

namespace GrailTechnology.AutoTags.DataType
{
    public class Helper
    {
        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        static Helper instance = null;

        private Helper()
        {
        }

        public static Helper Instance
        {
            get
            {
                if (instance == null) {
                    instance = new Helper();
                }

                return instance;
            }
        }

        public string RemoveHTML(string html)
        {
            return umbraco.library.StripHtml(html);
        }
        
        public string GetFormProperties(NameValueCollection form, List<string> sanitizedKeys)
        {
            var content = new StringBuilder();
            foreach (string key in sanitizedKeys)
            {
                string v = RemoveHTML(form[key]).Trim();
                if (v.Length > 0)
                {
                    log.Debug("Adding value from form key: " + key);
                    if (v.EndsWith(".") || v.EndsWith(",") || v.EndsWith("?") || v.EndsWith("!"))
                    {
                        content.AppendFormat("{0} ", v);
                    }
                    else
                    {
                        content.AppendFormat("{0}. ", v);
                    }
                }
            }

            return content.ToString();
        }
    }
}